package com.lihao.wanandroid.ui.home.recommend

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lihao.wanandroid.R
import com.lihao.wanandroid.app.ext.setAdapterAnimation
import com.lihao.wanandroid.data.model.ArticleResponse

/**
 * Created by lihao on 2020/5/22.
 * Describe: 首页文章列表adapter
 */
class ArticleAdapter() :
    BaseQuickAdapter<ArticleResponse, BaseViewHolder>(R.layout.item_home_article), LoadMoreModule {

    init {
        setAdapterAnimation(2)
        addChildClickViewIds(R.id.tvCollect)
    }

    override fun convert(
        holder: BaseViewHolder,
        item: ArticleResponse
    ) {
        item.run {
            holder.setText(R.id.tvAuthor, if (author.isEmpty()) shareUser else author)
            holder.setGone(R.id.tvFresh, !fresh)
            holder.setGone(R.id.tvStick, type != 1)
            holder.setText(R.id.tvCollect, if (collect) "已收藏" else "+ 收藏")
            holder.setTextColorRes(
                R.id.tvCollect,
                if (collect) R.color.tagColorGray else R.color.colorPrimary
            )
            holder.setText(R.id.tvTitle, title)
            holder.setText(R.id.tvChapterName, "$superChapterName.$chapterName")
            holder.setText(R.id.tvTime, niceDate)
        }
    }
}